//
//  HeaderView.m
//  签到
//
//  Created by Burn on 2018/12/13.
//  Copyright © 2018 nmgxysh. All rights reserved.
//

#import "HeaderView.h"
#import <Masonry.h>
#import "NSString+Base.h"
@interface HeaderView()

/***/
@property(strong,nonatomic) NSArray *dayArray;

/***/
@property(strong,nonatomic) UILabel *topLabel;

@end

@implementation HeaderView

static CGFloat lineSpacing = 5;
static CGFloat itemMax = 7;

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor redColor];
        [self setupSubViews];
    }
    return self;
}


- (void)setupSubViews{
    
    
    
    self.topLabel = [[UILabel alloc]init];
    self.topLabel.frame = CGRectMake(0, 5, self.frame.size.width, 10);
    self.topLabel.textAlignment = NSTextAlignmentCenter;
    self.topLabel.font = [UIFont systemFontOfSize:14];
    self.topLabel.textColor = [UIColor whiteColor];
    [self addSubview:self.topLabel];
    

    CGFloat wh = ([UIScreen mainScreen].bounds.size.width - (itemMax - 1) * lineSpacing) / 7;
    for (int i = 0; i < 7; i++) {
        UILabel *label = [[UILabel alloc]init];
        label.font = [UIFont systemFontOfSize:14];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor whiteColor];
        label.frame = CGRectMake((wh + lineSpacing) * i, CGRectGetMaxY(self.topLabel.frame) + 5, wh, self.bounds.size.height - CGRectGetMaxY(self.topLabel.frame) - 5);
        label.text = [NSString stringWithFormat:@"%@",self.dayArray[i]];
        [self addSubview:label];
    }
}

- (void)setTitleText:(NSString *)titleText{
    self.topLabel.text = titleText;
}

- (NSArray *)dayArray{
    if (!_dayArray) {
        _dayArray = @[@"一",@"二",@"三",@"四",@"五",@"六",@"日",];
    }
    return _dayArray;
}

@end
